package com.wcx.application.controller;

import com.wcx.application.domian.IndustriesBean;
import com.wcx.application.domian.TechnologyBean;
import com.wcx.application.service.IndustriesService;
import com.wcx.application.service.TechnologyService;
import com.wcx.application.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/technology")
@CrossOrigin
public class TechnologyController {

    @Autowired
    TechnologyService technologyService;


    @GetMapping("/list")
    public Result getList() {
        System.out.println("---" + technologyService.getList());
        return Result.ok().data("list", technologyService.getList());
    }

    @PostMapping("/update")
    public Result update(@RequestBody TechnologyBean technologyBean) {
        int i = technologyService.update(technologyBean);
        if (i != 0) {
            return Result.ok();
        } else {
            return Result.error();
        }
    }

    @PostMapping("/search")
    public Result search(@RequestBody  TechnologyBean technologyBean) {
        return Result.ok().data("list", technologyService.searchList(technologyBean));
    }

    @PostMapping("/create")
    public Result create(@RequestBody TechnologyBean technologyBean) {

        int i = technologyService.create(technologyBean);
        if (i != 0) {
            return Result.ok();
        } else {
            return Result.error();
        }

    }

    @DeleteMapping("/delete")
    public Result delete(int id) {
        int i = technologyService.delete(id);
        if (i != 0) {
            return Result.ok();
        } else {
            return Result.error();
        }
    }
}